<?php
namespace backend\models;

use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
use common\models\Admin;

/**
 * Clue model
 *显示字段

 */
class FollowInfos extends ActiveRecord
{
    const STATUS_DELETED = 0;
    const STATUS_ACTIVE = 10;


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%follow_infos}}';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => 'yii\behaviors\TimestampBehavior',
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => [


                    ],
                    ActiveRecord::EVENT_BEFORE_UPDATE => [

                    ]
                ]
            ]
        ];
    }

    /**
     * @inheritdoc
     */
   /* public function rules()
    {
        return [
            ['status', 'default', 'value' => self::STATUS_ACTIVE],
            ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
        ];
    }
   */


    public static function findByUsername($username)
    {
        return static::findOne(['userName' => $username]);
    }
    /**
     * 线索来源
     */
    public function getClueOrgin(){
        return static::hasOne(ClueOrgin::className(),['id'=>'clueOrgin']);
    }
    /**
     * 绑定和跟进状态的关系
     */

    public function getFollowType(){
        return static::hasOne(FollowType::className(),['id'=>'followType'])->from(['types'=>FollowType::tableName()]);
    }
    public function getFollowStatus(){
        return static::hasOne(FollowType::className(),['id'=>'followStatus'])->from(['status'=>FollowType::tableName()]);;
    }
    /**
     * 绑定和配合度的关系
     */
    public function getCoordinationDegree(){
        return static::hasOne(CoordinationDegree::className(),['id'=>'coordinationId']);
    }
    /**
     * 绑定与客服之间的关系也就是员工
     */
    public function getUsers(){
        return static::hasOne(Admin::className(),['id'=>'responUserId']);
    }



}
